

//全局变量
var mppId,activeId;

var dianzan_button=document.getElementById("dianzan_button");
dianzan_button.onclick=function(){
	ajax({
		url:"http://www.antmall.cc/public/wx/collect/data/checkVote.html"+"?"+"mppId="+mppId,
		success:function(data){
			var data = JSON.parse(data);
			if(!data.code){
				var req = {"mppId":mppId};
				$.post(
					"http://www.antmall.cc/public/wx/collect/data/checkVote.html",
					req,
					function(res){
						window.location.href="woyaojizan.html";
				});	
			}
		}
	});
}
var help=document.getElementsByClassName("help")[0];
help.onclick=function(){
	ajax({
		url:"http://www.antmall.cc/public/wx/collect/data/checkVote.html"+"?"+"mppId="+mppId,
		success:function(data){
			var data = JSON.parse(data);
			if(!data.code){
				console.log(data.code);
				var req = {"mppId":mppId};
				$.post(
					"http://www.antmall.cc/public/wx/collect/data/checkVote.html",
					req,
					function(res){
						window.location.href="woyaojizan.html";
				});	
			}
		}
	});

}

ajax({
	url:"http://www.antmall.cc/public/wx/collect/data/"+activeId+"/"+mppId+".html",
	success:function(data){
		var info = JSON.parse(data);
		var gift=info.data.gift;
		var giftReceive=info.data.giftReceive;
		var num=giftReceive.giftTotal;
		var join_num=giftReceive.likedTotal;
		var oImg=document.getElementsByClassName("left")[0];
		var title=document.getElementsByClassName("name")[0];
		var total_num=document.getElementsByClassName("totalNum")[0];
		var address=document.getElementsByClassName("address")[0];
		var price_num=document.getElementsByClassName("price_num")[0];
		var top_goods=document.getElementsByClassName("top")[0];
		var user=document.getElementsByClassName("user")[0];
		var people_num=document.getElementsByClassName("people_num")[0];
		
		top_goods.onclick=function(){
			window.location.href="goodsinfo.html";
		}
		people_num.innerHTML=num-join_num;
		user.style.backgroundImage = "url("+info.data.userInfo.headImgUrl+")";
		oImg.style.backgroundImage = "url("+gift.giftImg+")";
		title.innerHTML=giftReceive.title;
		total_num.innerHTML=giftReceive.giftTotal;
		address.innerHTML=info.data.active.bizShop.address;
		price_num.innerHTML=(giftReceive.giftPrice)/100;

		var xs_center=document.getElementsByClassName("xs_center")[0];
		xs_center.innerHTML=gift.samples;


	}
})

function ajax(info){
	if(window.XMLHttpRequest){
		var xhr = new XMLHttpRequest();	
	}else{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url = info.url;
	var type = info.type||"GET";
	var data = info.data||"";
	
	if(type=="GET"){
		xhr.open("GET",url,true);
		xhr.send();
	}else{
		xhr.open("POST",url,true);
		xhr.setRequestHeader("myHeader","myvalue");
		xhr.send(data);
	}
	
	xhr.onload = function(){
		if(info.success){
			info.success(xhr.responseText);
		}
	}
}

